package operation;

import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation {
    @Override
    public void work(BookList bookList) {
        System.out.println("请输入图书名：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUsedSize(); i++) {
            if(bookList.findBook(i).getName().equals(name)) {
                if(!bookList.findBook(i).isBorrowed()) {
                    System.out.println("该图书未被借出...");
                    return;
                }
                bookList.findBook(i).setBorrowed(false);
                System.out.println("归还图书成功");
                return;
            }
        }
        System.out.println("该图书尚未添加...");
    }
}
